<template>
  <div class="cartcontrol">
    <transition name="move">
      <div v-show="food.count" class="cart-decrease" @click.stop="decrease">
        <div class="inner icon-remove_circle_outline"></div>
      </div>
    </transition>
    <div v-show="food.count" class="cart-count">{{food.count}}</div>
    <div class="cart-add icon-add_circle" @click.stop="add"></div>
  </div>
</template>
<script>
const EVENT_ADD = 'add'

export default {
  name: 'cart-control',
  props: {
    food: {
      type: Object,
      default() {
        return {}
      }
    }
  },
  methods: {
    add(event) {
      if (!this.food.count) {
        this.$set(this.food, 'count', 1)
      } else {
        this.food.count++
      }
      this.$emit(EVENT_ADD, event.target)
    },
    decrease() {
      if (this.food.count) {
        this.food.count--
      }
    }
  }
}
</script>
<style lang="stylus" scoped>
@import '../../common/stylus/variable.styl'

.cartcontrol
  display flex
  .cart-decrease
    margin-right 8px
    opacity 1
    .inner
      color $color-blue
      font-size $fontsize-large-xxx
      transition all 0.2s linear
      transform rotate(0)
    &.move-enter-active, &.move-leave-active
      transition all 0.2s linear
    &.move-enter, &.move-leave-active
      opacity 0
      transform translate3d(24px, 0, 0)
      .inner
        transform rotate(180deg)
  .cart-count
    line-height 24px
    width 14px
    margin-right 8px
    text-align right
    font-size $fontsize-small-s
    color $color-text-ss
  .cart-add
    color $color-blue
    font-size $fontsize-large-xxx
</style>
